思路主要来自:http://www.infoq.com/cn/news/2011/03/xxb-maven-5-integration-test/ Maven实战(五)——自动化Web应用集成测试
首先需要在测试前把应用服务器启动起来,并把war包部署到服务器上,这个主要是把jboss-as:start
和jboss-as:deploy
这两个goal绑定到pre-integration-test
阶段;另外在测试完之后要把服务器停掉,这个主要把jboss-as:shutdown
绑定到post-integration-test
阶段
<build>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.7.Final</version>
<executions>
<excution>
<id>jboss-start-deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<name>${project.artifactId}.${project.packaging}</name>
</configuration>
</excution>
<excution>
<id>jboss-shutdown</id>
<phase>post-integration-test</phase>
<goals>
<goal>shtudown</goal>
</goals>
</excution>
</executions>
</plugin>
</build>
另外,需要将集成测试的类命名为不含有Test
(例如改为以*IT.java
命名),否则在单元测试阶段会执行这些测试案例,之后需要将这些测试的执行绑定到integration-test
阶段:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<excution>
<id>run-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</excution>
</executions>
</plugin>
</build>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。